﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace WFI.common.Extension
{
    public static class ObjectExtension
    {
        /// <summary>
        /// 对象的深度拷贝
        /// </summary>
        public static object Clone(this object ldc)
        {
            BinaryFormatter Formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            Formatter.Serialize(stream, ldc);
            stream.Position = 0;
            object clonedObj = Formatter.Deserialize(stream);
            stream.Close();
            return clonedObj;
        }
    }
}
